package com.cancer.common.web;

import java.util.List;

/**
 * 2016年4月16日 @author 刘俊
 * 增加泛型支持 
 * 
 * @company GeekPlus
 * @project beetle
 * @since 1.0.0
 */
public class PageBean<T> {
	/** 客户端传递的参数 **/
	private int currentPage;
	private int pageSize;

	/** 查询得出 **/

	private List<T> recordList;
	private long recordCount;

	/** 计算得出 **/
	private int pageCount;
	private int beginPageIndex;
	private int endPageIndex;

	public PageBean() {
		super();
	}

	public PageBean(int currentPage, int pageSize, long recordCount, List<T> recordList) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.recordList = recordList;
		this.recordCount = recordCount;

		// 计算页数
		int selectCount = (int) (recordCount % pageSize);
		// 判断总记录数与每页条数取余后是否为0
		if (selectCount == 0) {
			this.pageCount = (int) (recordCount / pageSize);
		} else {
			this.pageCount = (int) (recordCount / pageSize) + 1;
		}
		// 判断当前页是否大于总页数
		if (currentPage > this.pageCount) {
			// 将当前页就设为总页数
			this.currentPage=this.pageCount;
		}

		// 计算 beginPageIndex 与 endPageIndex
		// >> 总页码小于等于10页时，全部显示
		if (pageCount <= 10) {
			beginPageIndex = 1;
			endPageIndex = pageCount;
		}
		// >> 总页码大于10页时，就只显示当前页附近的共10个页码
		else {
			// 默认显示 前4页 + 当前页 + 后5页
			beginPageIndex = currentPage - 4; // 7 - 4 = 3;
			endPageIndex = currentPage + 5; // 7 + 5 = 12; --> 3 ~ 12

			// 如果前面不足4个页码时，则显示前10页
			if (beginPageIndex < 1) {
				beginPageIndex = 1;
				endPageIndex = 10;
			}
			// 如果后面不足5个页码时，则显示后10页
			else if (endPageIndex > pageCount) {
				endPageIndex = pageCount;
				beginPageIndex = pageCount - 9;
			}
		}
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getRecordList() {
		return recordList;
	}

	public void setRecordList(List<T> recordList) {
		this.recordList = recordList;
	}

	public long getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(long recordCount) {
		this.recordCount = recordCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public int getBeginPageIndex() {
		return beginPageIndex;
	}

	public int getEndPageIndex() {
		return endPageIndex;
	}

}
